<?php
Namespace Cyfy\Modules\Menu;

use \Cyfy\Message;

/**
 * Class for menu navigations.
 *
 * @version 0.1
 * @author Dandelion
 */ 
class Module extends \Cyfy\Module
{
    
    /**
     * Administration interface.
     * @return mixed
     */
	static function administration($name = "")
	{
        switch($name)
        {
            case "menus":
                return Administration :: menus();
                
            case "":
                return array(
                    "menus" => array("name" => self :: t(10), "description" => self :: t(20), "permission" => "create and edit"),
                );
		}
	}
    
    
    /**
     * Ajax callbacks
     */
	static function ajax($name)
	{
		switch($name)
		{
			case "save":
				return Administration :: save($_POST["mid"]);
			
			case "delete":
				return Administration :: delete($_POST["mid"]);
		}
	}
	
    /**
     * BLOCKS
     */
	static function blocks($name = '')
	{
		// if loading block
		if($name)
		{
			return Menu :: load($name);
		}

		// else show menu list
        $result = \dibi :: query("SELECT [code],[name] FROM [:cyfy:Menu-menus] ORDER BY [name] ASC");
        return $result -> fetchPairs('code', 'name');
	}
}
